<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>食材管理</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<!-- Bootstrap -->
    <link href="<%=basePath%>bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen">
    <link href="<%=basePath%>bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet" media="screen">
    <link href="<%=basePath%>assets/styles.css" rel="stylesheet" media="screen">
    <link href="<%=basePath%>assets/DT_bootstrap.css" rel="stylesheet" media="screen">
    <!--[if lte IE 8]><script language="javascript" type="text/javascript" src="vendors/flot/excanvas.min.js"></script><![endif]-->
    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
    <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <script src="<%=basePath%>vendors/modernizr-2.6.2-respond-1.1.0.min.js"></script>
  </head>
  
  <body>
  <%
    if(request.getSession().getAttribute("acc") == null) {
        response.sendRedirect("../emp/adminLogin");
    }
%>
    <div class="navbar navbar-fixed-top">
    <div class="navbar-inner">
        <div class="container-fluid">
            <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </a>
           <a class="brand">麦包郎后台管理系统</a>
            <div class="nav-collapse collapse">

                <ul class="nav">


                    <li class="dropdown">

                        <ul class="dropdown-menu">
                            <li>
                                <a tabindex="-1" href="#">用户列表</a>
                            </li>
                            <li>
                                <a tabindex="-1" href="#">搜索</a>
                            </li>
                            <li>
                                <a tabindex="-1" href="#">权限</a>
                            </li>
                        </ul>
                    </li>
                </ul>
            </div>
            <!--/.nav-collapse -->
        </div>
    </div>
</div>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span3" id="sidebar">
            <ul class="nav nav-list bs-docs-sidenav nav-collapse collapse">
                <li>
					<a href="<%=basePath%>emp/getAll"><i class="icon-chevron-right"></i> 店铺管理</a>
				</li>
					
				<li>
					<a href="<%=basePath%>shop/today"><i class="icon-chevron-right"></i>今日订单 </a>
				</li>

				<li>
					<a href="<%=basePath%>ord/selectli"><i class="icon-chevron-right"></i> 历史订单</a>
				</li>

						
				<li class="active">
					<a href="<%=basePath%>commodity/tong"><i class="icon-chevron-right"></i>食材管理</a>
				</li>
				<li>
					<a href="<%=basePath%>ord/caiwu"><i class="icon-chevron-right"></i>财务管理</a>
				</li>

            </ul>
        </div>
        <!--/span-->
        <div class="span9" id="content">


            <div class="row-fluid">
                <!-- block -->
                <div class="block">
                    <div class="navbar navbar-inner block-header">
                        <div class="muted pull-left">食材管理</div>


                           
                            <button style="margin-left: 10px;" id="xinzheng" class="btn btn-danger">新增</button>
                     <button style="margin-left: 20px;" id="shangjia" onclick="state(1)" class="btn btn-info">全部上架</button>
                        <button style="margin-left: 10px;" id="xiajia" onclick="state(0)" class="btn btn-danger">全部下架</button>
                  
                    </div>
                    <div class="block-content collapse in">
                        <div class="span12">
                            <div class="table-toolbar">


                            </div>

                            <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example2">
                                <thead>
                                <tr>
                                    <th>货物名称</th>
                                    <th>价格</th>
                                    <th>规格</th>
                                    <th>单位</th>
                                    <th>修改</th>
                                    <th>删除</th>
                                    <th>本日销售数量</th>
                                    <!--<th>库存</th>-->
                                    <th>本月销售数量</th>
                                     <th>本年销售数量</th>
                                    <th>上下架</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach items="${list}" var="li">
                                <tr class="odd gradeX">
                                    <td>${li.name}</td>
                                    <td>${li.price}</td>
                                    <td>${li.weight}</td>
                                    <td>${li.danwei}</td>
                                    <td class="center">

                                        <button  class="xiugai" onclick="update(${li.id})">修改</button></td>

                                    <td class="center">

                                        <button  onclick="javascript:return del(${li.id});"  class="btn btn-danger">删除</button></td>
                                    <td class="center">

                                        <p >${li.daytotal}</p></td>
                                    <td class="center">

                                        <p >${li.total}</p></td>
                                         <td class="center">

                                        <p >${li.yeartotal}</p></td>
                                    <td class="center">
<c:if test="${li.isMai==false}">
                                        <button   class="btn btn-info" onclick="updateState(${li.id},1)">上架</button>
                                        </c:if><c:if test="${li.isMai==true}">
                                        <button   class="btn btn-danger" onclick="updateState(${li.id},0)">下架</button>
                                        </c:if>
                                    </td>
                                </tr>
							</c:forEach>

                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <!-- /block -->
            </div>
        </div>
    </div>
    <hr>

</div>
<!--/.fluid-container-->


<!--新增开始-->
<div style=" display: none;
            z-index:999999;
            position: absolute;
            top: 25px;" id="rrr" class="row-fluid">

    <div class="block">
        <div class="navbar navbar-inner block-header">
            <div class="muted pull-left">新增货物</div>
        </div>
        <div class="block-content collapse in">
            <div class="span12">
                <form class="form-horizontal" method="post" action="commodity/saveAndUpdate" enctype="multipart/form-data">
                    <fieldset>
                        <legend>新增货物</legend>
                        <div class="control-group">
                            <label class="control-label">货物类别</label>
                            <div class="controls">
                                <select class="span6 m-wrap" name="typeid">
									<c:forEach items="${tList}" var="t">
										 <option value="${t.id}">${t.typeName}</option>
									</c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="typeahead">货物名称 </label>
                            <div class="controls">
                                <input type="text" name="name" class="span6" id="typeahead"  data-provide="typeahead" data-items="4" data-source='["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Dakota","North Carolina","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"]'>

                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="typeahead">价格/元 </label>
                            <div class="controls">
                                <input type="number" step="0.001" name="price" class="span6" id="typeahead2"  data-provide="typeahead" data-items="4" data-source='["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Dakota","North Carolina","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"]'>

                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="typeahead">规格</label>
                            <div class="controls">
                                <input type="text" name="weight" class="span6" id="typeahead3"  data-provide="typeahead" data-items="4" data-source='["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Dakota","North Carolina","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"]'>

                            </div>
                        </div>
                         <div class="control-group">
                            <label class="control-label" for="typeahead">单位</label>
                            <div class="controls">
                                <input type="text" name="danwei" class="span6" id="typeahead8"  data-provide="typeahead" data-items="4" data-source='["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Dakota","North Carolina","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"]'>

                            </div>
                        </div>


                        <div class="control-group">
                            <label class="control-label" for="fileInput">上传图片</label>
                            <div class="controls">
                                <input class="input-file uniform_on" id="fileInput" name="file" type="file">
                            </div>
                        </div>

                        <div class="form-actions">
                            <button id="queren" type="submit" class="btn btn-primary">确认</button>
                            <button id="quxiao" type="reset" class="btn">取消</button>
                        </div>
                    </fieldset>
                </form>

            </div>
        </div>
    </div>

</div>
<!--新增结束-->




<!--修改货物开始-->
<div style=" display: none;
            z-index:999999;
            position: absolute;
            top: 25px;" id="rrr1" class="row-fluid">

    <div class="block">
        <div class="navbar navbar-inner block-header">
            <div class="muted pull-left">修改货物</div>
        </div>
        <div class="block-content collapse in">
            <div class="span12">
                <form class="form-horizontal"   method="post" action="commodity/saveAndUpdate" enctype="multipart/form-data">
                    <fieldset>
                        <legend>修改货物</legend>
                        <div class="control-group">
                            <label class="control-label">货物类别</label>
                            <div class="controls">
                                <select class="span6 m-wrap" name="typeid">
									<c:forEach items="${tList}" var="t">
										 <option value="${t.id}">${t.typeName}</option>
									</c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="typeahead">货物名称 </label>
                            <div class="controls">
                                <input type="text" name="name" class="span6" id="typeahead4"  data-provide="typeahead" data-items="4" data-source='["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Dakota","North Carolina","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"]'>
								<input id="id1" type="hidden" value="0" name="id"/>
                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="typeahead">价格/元 </label>
                            <div class="controls">
                                <input type="number" step="0.001" class="span6" name="price" id="typeahead5"  data-provide="typeahead" data-items="4" data-source='["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Dakota","North Carolina","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"]'>

                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="typeahead">规格</label>
                            <div class="controls">
                                <input type="text" class="span6" id="typeahead6" name="weight"  data-provide="typeahead" data-items="4" data-source='["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Dakota","North Carolina","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"]'>

                            </div>
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="typeahead">单位</label>
                            <div class="controls">
                                <input type="text" class="span6" id="typeahead7" name="danwei"  data-provide="typeahead" data-items="4" data-source='["Alabama","Alaska","Arizona","Arkansas","California","Colorado","Connecticut","Delaware","Florida","Georgia","Hawaii","Idaho","Illinois","Indiana","Iowa","Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts","Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska","Nevada","New Hampshire","New Jersey","New Mexico","New York","North Dakota","North Carolina","Ohio","Oklahoma","Oregon","Pennsylvania","Rhode Island","South Carolina","South Dakota","Tennessee","Texas","Utah","Vermont","Virginia","Washington","West Virginia","Wisconsin","Wyoming"]'>

                            </div>
                        </div>




                        <div class="control-group">
                            <label class="control-label" for="fileInput">上传图片</label>
                            <div class="controls">
                                <input class="input-file uniform_on" id="fileInput1" type="file" name="file">
                            </div>
                        </div>

                        <div class="form-actions">
                            <button type="submit" class="btn btn-primary">确认</button>
                            <button id="quxiao1" type="reset" class="btn">取消</button>
                        </div>
                    </fieldset>
                </form>

            </div>
        </div>
    </div>

</div>
<!--修改货物结束-->
<div>

</div>
<script src="<%=basePath%>vendors/jquery-1.9.1.js"></script>
<script src="<%=basePath%>bootstrap/js/bootstrap.min.js"></script>
<script src="<%=basePath%>vendors/datatables/js/jquery.dataTables.min.js"></script>


<script src="<%=basePath%>assets/scripts.js"></script>
<script src="<%=basePath%>assets/DT_bootstrap.js"></script>

</body>
<script>
    var xinzheng = document.getElementById("xinzheng");
    var quxiao = document.getElementById("quxiao");
    var rrr = document.getElementById("rrr");
    var xiugai = document.getElementsByClassName("xiugai");
    var xiangqing = document.getElementsByClassName("xiangqing");
    xinzheng.onclick = function () {
        rrr.style.display = "block";
    }
    quxiao.onclick = function () {
      rrr.style.display = "none";
    }

    quxiao1.onclick = function () {
        rrr1.style.display = "none";
    }

    for(var j=0;j<xiugai.length;j++){
        xiangqing[j].onclick = function () {
            window.location.href="<%=basePath%>admin/editors.jsp";
        };
    }




    function del(id) {
        var msg = "您真的确定要删除吗？\n\n请确认！";
        if (confirm(msg)==true){
             window.location.href="commodity/shan?id="+id;
        }else{
            return false;
        }
    }
    
    function update(id){
    rrr1.style.display = "block";
    	 $.ajax({
             type: "GET",
             url: "commodity/getById",
             data: {id:id},
             dataType: "json",
             success: function(data){
                //var json=eval("("+data+")");
                //alert(data.id); 
                $("#typeahead4").val(data.name);
                $("#id1").val(data.id);
                $("#typeahead5").val(data.price);
                $("#typeahead6").val(data.weight);
                $("#typeahead7").val(data.danwei);
         	 }
         });
    }
  
    function state(state){
    	if(state==1){
    		window.location.href="commodity/updateState?isMai="+true;
    		 if(isMai==true){
    		    	$("#xiajia").css("display","block");
    				$("#shangjia").css("display","none");
    		    }
    		
    	}else{
    		window.location.href="commodity/updateState?isMai="+false;
    		 if(isMai==false){
    		    	$("#xiajia").css("display","none");
    				$("#shangjia").css("display","block");
    		    }
    	}
    }

    
    
    function updateState(id,state){
    	if(state==1){
    		window.location.href="commodity/updateState?isMai="+true+"&id="+id;
    	}else{
    		window.location.href="commodity/updateState?isMai="+false+"&id="+id;
    	}
    }
</script>
  </body>
</html>
